package com.gy.wx_demo_mg.service.manageruser;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gy.wx_demo_mg.dao.ManagerUserDao;
import com.gy.wx_demo_mg.entity.ManagerUser;
import com.gy.wx_demo_mg.service.serviceinterface.ManagerUserService;
import com.gy.wx_demo_mg.utils.RSon;

@Service("managerUserService")
public class ManagerUserServiceImp implements ManagerUserService {
    
    private static Logger logger = LoggerFactory.getLogger(ManagerUserServiceImp.class);
    
    @Autowired
    private ManagerUserDao managerUserDao;

    @Override
    public void addManagerUser(ManagerUser user, RSon rson) {
        handUser(user);
        Integer userId;
        try {
            userId = managerUserDao.insertIntoManagerUserOneUser(user);
        } catch (Exception e) {
            logger.error("新增管理员用户数据库操作异常:"+e.getMessage(),e);
            RSon.error(rson, RSon.DAO_ERROR_CODE);
            return;
        }
        user.setUserId(userId);
        //rson.setData(user);
    }
    
    private void handUser(ManagerUser user){
        if(user.getStatus()==null){
            user.setStatus(ManagerUser.USER_STATUS_1);
        }
        if(user.getCreateTime()==null){
            user.setCreateTime(new Date());
        }
    }

    

}
